package com.fengke.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.fengke.dao.division.DivisionManager;
import com.fengke.dao.model.DepartureModel;
import com.fengke.dao.model.DestinationModel;
import com.fengke.service.DivisionService;
import com.fengke.service.vo.DepartureVO;
import com.fengke.service.vo.DestinationVO;

public class DivisionServiceImpl implements DivisionService {
	private DivisionManager divisionManager;
	public List<DepartureVO> researchDepartureVOList(DepartureVO departureVO, int offset, int limit) throws Exception {
		if(departureVO.getDepartureModel() == null) {
			departureVO.setDepartureModel(new DepartureModel());
		}
		List<DepartureModel> departureModelList = divisionManager.researchDepartureModelList(departureVO.getDepartureModel(), offset, limit);
		if(departureModelList != null && departureModelList.size() > 0) {
			List<DepartureVO> voList = new ArrayList<DepartureVO>();
			for(DepartureModel model : departureModelList) {
				DepartureVO vo = new DepartureVO();
				vo.setDepartureModel(model);
				voList.add(vo);
			}
			return voList;
		}
		return null;
	}
	public List<DestinationVO> researchDestinationVOList(DestinationVO destinationVO, int offset, int limit) throws Exception {
		if(destinationVO.getDestinationModel() == null) {
			destinationVO.setDestinationModel(new DestinationModel());
		}
		List<DestinationModel> destinationModelList = divisionManager.researchDestinationModelList(destinationVO.getDestinationModel(), offset, limit);
		if(destinationModelList != null && destinationModelList.size() > 0) {
			List<DestinationVO> voList = new ArrayList<DestinationVO>();
			for(DestinationModel model : destinationModelList) {
				DestinationVO vo = new DestinationVO();
				vo.setDestinationModel(model);
				voList.add(vo);
			}
			return voList;
		}
		return null;
	}
	@Override
	public DepartureVO createDeparture(DepartureVO departureVO) throws Exception {
		departureVO.getDepartureModel().setId(divisionManager.createDeparture(departureVO.getDepartureModel()));
		return departureVO;
	}
	@Override
	public DepartureVO updateDepartureById(DepartureVO departureVO) throws Exception {
		divisionManager.updateDepartureById(departureVO.getDepartureModel());
		return departureVO;
	}
	@Override
	public DestinationVO createDestination(DestinationVO destinationVO) throws Exception {
		destinationVO.getDestinationModel().setId(divisionManager.createDestination(destinationVO.getDestinationModel()));
		return destinationVO;
	}
	@Override
	public DestinationVO updateDestinationById(DestinationVO destinationVO) throws Exception {
		divisionManager.updateDestinationById(destinationVO.getDestinationModel());
		return destinationVO;
	}
	@Override
	public void deleteDepartureByIds(List<String> list) throws Exception {
		divisionManager.deleteDepartureByIds(list);
	}
	@Override
	public void deleteDestinationByIds(List<String> list) throws Exception {
		divisionManager.deleteDestinationByIds(list);
	}
	public DivisionManager getDivisionManager() {
		return divisionManager;
	}
	public void setDivisionManager(DivisionManager divisionManager) {
		this.divisionManager = divisionManager;
	}
}
